package servlet;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import BLL.BProduct;
import BLL.BUser;
import DTO.Product;
import DTO.User;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Vien-IT
 */
public class ListProduct extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
   

    
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
            String categoryId = request.getParameter("categoryId");
        PrintWriter out = response.getWriter();
        System.out.println(Integer.parseInt(categoryId));
        ArrayList<Product> products = new BProduct().getByCategoryId(Integer.parseInt(categoryId));
        if(products !=null)
        {
            out.println(Integer.parseInt(categoryId));
            for(Product p : products)
            {
                out.println(p.getName());
            }
        }
        request.setAttribute("listProduct", products);
        response.sendRedirect("index.jsp");
        
        
       
    }
}
    

